import { InjectionKey } from "vue";
import { createStore, Store } from "vuex";

// 为 store state 声明类型
export interface State {
  deck: number[];
  index: number;
}
// 定义 injection key
export const key: InjectionKey<Store<State>> = Symbol();

export const store = createStore<State>({
  state: {
    deck: [1, 2, 3, 4, 5],
    index: -1,
  },
  getters: {},
  mutations: {
    // 通过下标决定选中的牌
    CHANGE_INDEX(state, index) {
      state.index = index;
    },
    // +号增加牌的点数
    ADD_DECK_ITEM(state) {
      state.deck[state.index]++;
    },
    // 洗牌
    SORT_DECK(state) {
      state.deck = state.deck.sort((a, b) => {
        return a - b;
      });
    },
  },
  actions: {},
  modules: {},
});
